<template>
  <div class="order">
    <div class="left">
      <div class="top flex">
        <div class="workorder">
          <div class="title flex">
            <div>工单管理</div>
            <SelectNetwork :width="`150px`" />
          </div>
          <div v-if="worklist" class="tips flex">
            <div class="being">
              <div class="icon">
                <i class="el-icon-s-data" style="color: #2087d0" />
              </div>
              <div class="text">
                <div class="name">处理中</div>
                <div class="number" style="color: #2087d0">
                  {{ worklist.processing }}
                </div>
              </div>
            </div>
            <div class="overtime">
              <div class="icon">
                <i class="el-icon-s-data" style="color: #f4b259" />
              </div>
              <div class="text">
                <div class="name">即将超时</div>
                <div class="number" style="color: #f4b259">
                  {{ worklist.aboutToTimeOut }}
                </div>
              </div>
            </div>
            <div class="timeout">
              <div class="icon">
                <i class="el-icon-s-data" style="color: #f45959" />
              </div>
              <div class="text">
                <div class="name">已超时(T-4)</div>
                <div class="number" style="color: #f45959">
                  {{ worklist.timedOut }}
                </div>
              </div>
            </div>
          </div>
          <div class="notice">客服冬等1人近期存在已超时工单</div>
          <div class="chart">
            <LinearGradient
              :option-data="worklist != null ? worklist.map : null"
            />
          </div>
        </div>
        <div class="loss">
          <div class="title flex">
            <div>遗失率</div>
            <div class="date">
              <SelectMonthLight
                ref-name="0"
                :type="'date'"
                @getMonth="getDate"
              />
              <SelectMonthLight
                ref-name="1"
                :width="`100px`"
                @getMonth="getDate"
              />
            </div>
          </div>
          <div class="rate flex">
            <div class="flex">
              <Annulus
                :percentage="losetableData != null ? losetableData.lossRate : 0"
                :color="`#2087D0`"
                :stroke-width="10"
                :width="108"
              />
              <div class="text">
                <div>
                  遗失率&nbsp;&nbsp;&nbsp;{{
                    losetableData != null ? losetableData.lossRate : '0.00'
                  }}ppm
                </div>
                <div class="size">
                  遗失量&nbsp;&nbsp;&nbsp;{{
                    losetableData != null ? losetableData.lossCount : '0.00'
                  }}ppm
                </div>
              </div>
            </div>
            <div class="size">目标值&nbsp;&nbsp;&nbsp;--</div>
          </div>
          <el-table
            :data="losetableData != null ? losetableData.list : []"
            tooltip-effect="dark"
            border
          >
            <el-table-column
              label="承包区名称"
              align="center"
              prop="firstEnd"
            />
            <el-table-column label="遗失率" align="center" prop="lossCount" />
            <el-table-column label="遗失量" align="center" prop="lossRate" />
          </el-table>
        </div>
      </div>
      <div class="kpi flex">
        <div class="assess">
          <div class="title flex">
            <div>综合KPI考核</div>
            <SelectMonthLight :width="`100px`" />
          </div>
          <div class="item flex">
            <div class="text">今年交易总金额</div>
            <div class="detail"><span>0.04</span>元/票</div>
          </div>
          <div class="item flex">
            <div class="text">今年交易总金额</div>
            <div class="detail"><span>0.04</span>元/票</div>
          </div>
          <div class="item flex">
            <div class="text">今年交易总金额</div>
            <div class="detail"><span>0.04</span>元/票</div>
          </div>
        </div>
        <div class="stimulate">
          <div class="title">激励明细</div>
          <div class="table">
            <el-table height="260px" tooltip-effect="dark" border>
              <el-table-column label="激励梯度" align="center" width="150" />
              <el-table-column label="率值" align="center" width="120" />
              <el-table-column label="单票指标预估激励/元" align="center" />
              <el-table-column label="单票指标预估激励/元" align="center" />
            </el-table>
          </div>
        </div>
      </div>
    </div>
    <div class="right">
      <div class="trend">
        <div class="title">近7天回货趋势</div>
        <div class="chart">
          <div>
            <Annulus
              :percentage="
                aboutsevendata != null
                  ? aboutsevendata.nameAndListValueDtos[0].values[
                    aboutsevendata.nameAndListValueDtos[0].values.length - 1
                  ]
                  : 0
              "
              :color="`#2087D0`"
              :stroke-width="10"
              :width="108"
            />
            <div class="name">及时率</div>
          </div>
          <div class="title">
            <div>未及时量（4月24日）</div>
            <div>
              {{
                aboutsevendata != null
                  ? aboutsevendata.nameAndListValueDtos[1].values[
                    aboutsevendata.nameAndListValueDtos[1].values.length - 1
                  ]
                  : 0
              }}
              &nbsp;件<span>（考核量{{
                aboutsevendata != null
                  ? aboutsevendata.nameAndListValueDtos[2].values[
                    aboutsevendata.nameAndListValueDtos[2].values.length - 1
                  ]
                  : 0
              }}票）</span>
            </div>
          </div>
        </div>
        <div class="stack">
          <Stack :option-data="aboutsevendata" />
        </div>
      </div>
      <div class="today">
        <div class="title">今日回货</div>
        <div class="flex">
          <div v-if="returnTodayData" class="chart">
            <Annulus
              type="dashboard"
              :width="164"
              :stroke-width="20"
              :percentage="returnTodayData.schedule"
              stroke-linecap="square"
            />
            <div class="button">
              <el-button>回货进度</el-button>
            </div>
            <div class="flex">
              <div class="send">
                <div class="name">中心发货量（件）</div>
                <div class="number">{{ returnTodayData.deliveringAmount }}</div>
              </div>
              <div class="reply">
                <div class="name">未回货（件）</div>
                <div class="number">{{ returnTodayData.unreturnedGoods }}</div>
              </div>
            </div>
          </div>
          <div class="statis">
            <div class="name">各频次回货量</div>
            <div
              v-for="(item, index) in returnEveryData"
              :key="index"
              class="item"
            >
              <div class="flex">
                <div class="text">
                  {{ item.frequency
                  }}<span class="number">{{ item.deliveringAmount }}</span><span class="unit">件</span>
                </div>
                <div class="text">
                  <span class="number">{{ item.unreturnedGoods }}</span><span class="unit">件</span>未回货
                </div>
              </div>
              <Score :show-text="false" :percentage="item.schedule" />
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {
  getReturnWeek,
  getReturnToday,
  getReturnEvery,
  getWorkOrder,
  getLose
} from '@/api/workOrder'
// import { get } from 'js-cookie'
import { getDateYM, getDateYMD1 } from '@/utils/index'

export default {
  name: 'WorkOrder',
  data() {
    return {
      options: null,
      value: null,
      returnTodayData: null,
      returnEveryData: null,
      aboutsevendata: null,
      losetableData: null,
      worklist: null,
      from: {
        date: getDateYMD1(),
        pageDate: {
          pageNum: 1,
          pageSize: 10
        },
        yearMonth: getDateYM()
      }
    }
  },
  created() {
    this.init()
  },
  methods: {
    init() {
      this.getReturnWeekData()
      this.getReturnTodayData()
      this.getReturnEveryData()
      this.getWorkOrderData()

      this.getloseData()
    },
    // 遗失率yyyymmss
    getDate(obj) {
      console.log('时间', obj)
      if (obj.ref === '0') {
        this.from.date = obj.date
      } else {
        this.from.yearMonth = obj.date
      }
      this.getloseData()
    },
    // 遗失率
    async getloseData() {
      const res = await getLose(this.from)
      this.losetableData = res.data
    },
    getReturnWeekData() {
      getReturnWeek(0).then((res) => {
        console.log('七天量', res)

        this.aboutsevendata = res.data
      })
    },
    getReturnTodayData() {
      getReturnToday().then((res) => {
        this.returnTodayData = res.data
      })
    },
    getReturnEveryData() {
      getReturnEvery().then((res) => {
        this.returnEveryData = res.data
      })
    },
    getWorkOrderData() {
      getWorkOrder().then((res) => {
        this.worklist = res.data
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.order {
  padding: 30px 10px 30px 30px;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: space-between;
  background-color: #f5f5f5;

  .flex {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .title {
    font-weight: 500;
    font-size: 20px;
    color: #333;
  }

  .workorder,
  .loss,
  .kpi,
  .trend,
  .today {
    background: #ffffff;
    box-shadow: 0px 2px 2px 0px rgba(113, 121, 144, 0.06);
    border-radius: 8px;
  }

  .el-table {
    border-radius: 8px;

    &::v-deep .el-table__header tr th {
      background-color: #f5f5f5;
    }
  }

  .el-progress {
    &::v-deep .el-progress__text {
      font-size: 20px !important;
    }
  }

  .left {
    width: 1180px;

    .top {
      height: 510px;

      .workorder {
        padding: 24px;
        height: 100%;
        width: 626px;

        .tips {
          padding: 20px 0;
          border-bottom: 1px solid #ebecee;

          & > div {
            padding: 12px 16px;
            display: flex;
            width: 186px;
            height: 72px;
            background: #f4fbff;
            border-radius: 4px;
          }

          .icon {
            width: 48px;
            height: 48px;
            line-height: 48px;
            text-align: center;
            background: #e7f3fb;
            border-radius: 24px;
            font-size: 24px;
          }

          .text {
            margin-left: 16px;

            .name {
              font-weight: 400;
              font-size: 14px;
              color: #666666;
            }

            .number {
              font-size: 22px;
              line-height: 32px;
            }
          }
        }

        .notice {
          margin: 16px auto;
          width: 282px;
          height: 40px;
          line-height: 40px;
          text-align: center;
          background: #f7f1e8;
          border-radius: 4px;
          color: #666;
        }

        .chart {
          width: 578px;
          height: 249px;
          background: #fafafa;
          border-radius: 8px;
        }
      }

      .loss {
        padding: 24px;
        width: 534px;
        height: 100%;

        .date {
          & > div + div {
            margin-left: 16px;
          }
        }

        .rate {
          margin-top: 26px;
          margin-bottom: 26px;
          padding: 0 18px;
          font-size: 20px;

          .flex {
            .text {
              margin-left: 30px;
              line-height: 36px;
            }
          }

          .size {
            font-size: 16px;
            color: #666;
          }
        }
      }
    }

    .kpi {
      margin-top: 20px;
      height: 364px;

      .assess {
        padding: 24px;
        height: 100%;
        width: 440px;

        .item {
          margin-top: 20px;
          padding: 0 24px;
          width: 390px;
          height: 74px;
          border-radius: 8px;
          box-shadow: 0 0 8px 0 #2087d0 inset;

          .text {
            font-weight: 400;
            font-size: 18px;
            color: #333333;
          }

          .detail {
            font-weight: 400;
            font-size: 16px;
            color: #666;

            span {
              margin-right: 6px;
              font-size: 30px;
              color: #2087d0;
            }
          }
        }
      }

      .stimulate {
        padding-top: 32px;
        width: 740px;
        height: 100%;

        .title {
          padding-left: 30px;
          font-size: 18px;
        }

        .table {
          margin-top: 20px;
          padding-left: 30px;
          border-left: 1px solid #ebecee;

          .el-table {
            width: 680px;
          }
        }
      }
    }
  }

  .right {
    width: 660px;

    & > div {
      padding: 24px;
    }

    .trend {
      height: 528px;

      .chart {
        margin-top: 16px;
        padding-bottom: 18px;
        justify-content: center;
        display: flex;
        border-bottom: 1px solid #ebecee;

        .name {
          margin-top: 10px;
          text-align: center;
          color: #666;
        }

        .title {
          margin-top: 20px;
          margin-left: 30px;
          line-height: 36px;

          span {
            font-size: 16px;
            color: #999;
          }
        }
      }

      .stack {
        height: 310px;
      }
    }

    .today {
      margin-top: 20px;
      height: 346px;

      .chart {
        margin-right: 20px;
        width: 302px;
        text-align: center;

        .el-progress {
          margin-top: 20px;
          padding-right: 10px;

          &::v-deep .el-progress__text {
            font-size: 36px !important;
          }
        }

        .button {
          margin-top: -30px;

          .el-button {
            width: 96px;
            height: 36px;
            background: #ffffff;
            border-radius: 18px;
            border: 1px solid #9bcbeb;
            box-shadow: 0 0 08px 0 #2087d0 inset;
          }
        }

        .flex {
          margin-top: 16px;

          & > div {
            padding: 14px 16px;
            width: 144px;
            height: 72px;
            border-radius: 4px;

            .name {
              font-weight: 400;
              font-size: 14px;
              color: #666666;
            }

            .number {
              margin-top: 4px;
              font-weight: 500;
              font-size: 22px;
              color: #333333;
            }
          }

          .send {
            background: #e7f3fb;
          }

          .reply {
            background: #f7f1e8;
          }
        }
      }

      .statis {
        padding-left: 24px;
        width: 285px;
        height: 258px;
        border-left: 1px solid #ebecee;

        .name {
          margin-bottom: 10px;
          font-weight: 400;
          font-size: 16px;
          color: #333333;
        }

        .item {
          .flex {
            margin-bottom: 6px;

            .text {
              color: #999;

              .number {
                margin: 0 4px;
                font-size: 20px;
                color: #333;
              }

              .unit {
                color: #333;
              }
            }
          }
        }

        .item + .item {
          margin-top: 26px;
        }
      }
    }
  }
}
</style>
